package com.tianpengtech.common.validator.rules.string;


import com.tianpengtech.common.exception.ValidateException;
import com.tianpengtech.common.validator.AbstractRule;
import org.apache.commons.lang.StringUtils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class StringMustEngLish extends AbstractRule {
    private String rex = "^[A-Za-z]+$";

    public StringMustEngLish(String v, String msg) {
        this.value = v;
        this.msg = msg;
    }
    @Override
    public boolean validate() throws ValidateException {

        String v = StringUtils.trim((String) this.value);
        Pattern pattern = Pattern.compile(this.rex);
        Matcher matcher = pattern.matcher(v);
        if (!matcher.matches()) {
            throw new ValidateException(this.msg);
        }
        return false;
    }


    public static void main(String[] args) {

        StringMustEngLish s = new StringMustEngLish("code","必须是引文");
        try {
            s.validate();
        } catch (ValidateException e) {
            e.printStackTrace();
        }
    }
}
